package io.renren.modules.teacher.service.impl;

import cn.hutool.core.lang.Snowflake;
import io.renren.common.utils.PageUtils;
import io.renren.modules.teacher.dao.TeacherCourseManageDao;
import io.renren.modules.teacher.service.TeacherCourseManageService;
import io.renren.modules.teacher.service.TeacherPersonInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;
@Service
public class TeacherCourseManageImpl implements TeacherCourseManageService {
    @Autowired
    private TeacherCourseManageDao teacherCourseManageDao;
    /*
    分页查询列表
     */
    @Override
    public PageUtils queryList(Map<String, Object> params) {
        String teacherId = teacherCourseManageDao.queryTeacherId(params);
        params.put("teacherId",teacherId);
        List<Map<String, Object>> list = teacherCourseManageDao.queryList(params);
        int total = teacherCourseManageDao.queryTotal(params);
        int limit = Integer.parseInt(params.get("limit").toString());
        int page = Integer.parseInt(params.get("page").toString());
        PageUtils pageUtils = new PageUtils(list,total,limit,page);
        return pageUtils;
    }

    @Override
    public void save(Map<String, Object> dataForm) {
        //得到老师的id
        String teacherId = teacherCourseManageDao.queryTeacherId(dataForm);
        dataForm.put("teacherId",teacherId);
        Snowflake snowflake = new Snowflake(3L,10L);
        dataForm.put("courseInfoId",snowflake.nextId()+"");
        dataForm.put("date",new Date());
        teacherCourseManageDao.addCourse(dataForm);
    }
   /*
   查询表单数据
    */
    @Override
    public Map<String, Object> queryData(String courseId) {
        Map<String, Object> data = teacherCourseManageDao.queryData(courseId);
        return data;
    }
    /*
    修改课程
     */
    @Override
    public void update(Map<String, Object> dataForm) {
        teacherCourseManageDao.update(dataForm);

    }
   /*
   删除课程
    */
    @Override
    public void delete(String[] listIds) {
        teacherCourseManageDao.delete(listIds);
    }
    /*
    新增课程章节
     */
    @Override
    public void addChapter(Map<String, Object> form) {
        Snowflake snowflake = new Snowflake(3L,10L);
        form.put("chapterId",snowflake.nextId()+"");
        teacherCourseManageDao.addChapter(form);
    }
  /*
  获得章节
   */
    @Override
    public Map<String, Object> getChapter(String chapterId) {
         Map<String, Object> result = teacherCourseManageDao.getChapter(chapterId);
        return result;
    }
  /*
  更新章节内容
   */
    @Override
    public void updateChapter(Map<String, Object> formData) {
        teacherCourseManageDao.updateChapter(formData);
    }

    @Override
    public void delChapterContent(Map<String, Object> formData) {
        teacherCourseManageDao.delChapterContent(formData);
    }
}
